﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using OgilvyOne.Model;
using OgilvyOne.BLL;

public partial class admin_infomation_info_video_detail : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int aid = int.Parse(Request.Params["aid"]);

            CmsArticleModel cm = new CmsArticleBll().GetCmsArticleModel(aid);
            this.headers.Text = "当前位置：" + cm.Title + "&nbsp;&nbsp;<img src='../images/subnav_dot.gif' />&nbsp;&nbsp;视频详情";

            if (Request.Params["id"] != null && Request.Params["id"] != "")
            {
                int id = int.Parse(Request.Params["id"]);
                this.id.Value = id.ToString();
                CmsArticleVideoModel im = new CmsArticleVideoBll().GetVideoModel(id);
                this.video_name.Text = im.VideoName;
                this.video_file_name.Value = im.VideoFileName;
                this.video_order.Text = im.VideoOrder.ToString();
                this.state.Text = im.State.ToString();
                this.video_desc.Text = im.videoDesc;
            }
        }
    }

    protected void Sub_click(object sender, EventArgs e)
    {
        bool isup = false;
        if (this.id.Value != null && this.id.Value != "")
        {//update
            this.PopedomValidate(Request.Params["layerid"], MOD);
            CmsArticleVideoModel uim = GetPageModel();
            isup = new CmsArticleVideoBll().Update(uim);
            
            insertLog("修改文章视频:" + uim.VideoName);
        }
        else
        {//add
            this.PopedomValidate(Request.Params["layerid"], ADD);
            CmsArticleVideoModel uim = GetPageModel();
            uim.ArticleId = int.Parse(Request.Params["aid"]);
            uim.UserId = GetSessionUsersModel().Aid;
            uim.Add_time = DateTime.Now;
            isup = new CmsArticleVideoBll().Add(uim)>1;
            insertLog("新增文章视频:" + uim.VideoName);
            
        }
        if (isup) new CmsArticleBll().UpdateAudit(int.Parse(Request.Params["aid"]), GetSessionUsersModel().Username);
        Response.Redirect("info_video_list.aspx?aid=" + Request.Params["aid"] + "&layerid=" + Request.Params["layerid"]);
    }

    private CmsArticleVideoModel GetPageModel()
    {
        CmsArticleVideoModel avm = new CmsArticleVideoModel();
        if (this.id.Value != null && this.id.Value != "")
        {
            avm.VideoId = int.Parse(this.id.Value);
        }
        avm.VideoName = this.video_name.Text;
        avm.videoDesc = this.video_desc.Text;
        avm.VideoFileName = this.video_file_name.Value;
        if (this.video_order.Text != "")
        {
            avm.VideoOrder = int.Parse(this.video_order.Text);
        }

        avm.State = int.Parse(this.state.Text);
        return avm;
    }
}
